import type { FormInstance, FormRules } from "element-plus";
import { reactive, ref } from "vue";
import { formatTime } from "@/utils/date";

/**
 * @description 配置项
 */
export const headerConfig = [
  // {
  //   type: "input",
  //   // title: "角色名称",
  //   value: "orderId",
  //   clearable: true,
  //   width: "130",
  //   placeholder: "请输入订单号",
  // },
  {
    type: "input",
    // title: "角色名称",
    value: "courier",
    clearable: true,
    width: "130",
    placeholder: "请输入配送员",
  },
  {
    type: "input",
    // title: "角色名称",
    value: "initiator",
    clearable: true,
    width: "130",
    placeholder: "请输入发起人",
  },
  {
    type: "select",
    // title: "角色名称",
    value: "orderStatus",
    clearable: true,
    width: "150",
    placeholder: "请选择订单状态",
    options: [
      { label: "已发起", value: "CREATED" },
      { label: "配送中", value: "INDELIVERY" },
      { label: "已完成", value: "FINISH" },
    ],
  },
];

/**
 * @description 搜索数据
 */
export const configData = ref({
  orderId: "",
  courier: "",
  initiator: "",
  orderStatus: "",
});

/**
 * @description 表格配置
 */
export const tableConfig = [
  {
    prop: "order_id",
    label: "订单号",
    width: "90",
  },
  {
    prop: "originName",
    label: "仓库名称",
    width: "100",
  },
  {
    prop: "destinationName",
    label: "门面名称",
    width: "100",
    formatter: (row: any) =>
      row.destinationName ? row.destinationName : "入库订单",
  },
  {
    prop: "initiator",
    label: "发起人",
    width: "90",
  },
  {
    prop: "courier",
    label: "配送员",
    width: "90",
    formatter: (row: any) => (row.courier ? row.courier : "暂无配送员"),
  },
  {
    prop: "creation_time",
    label: "创建时间",
    // width: "150",
    formatter: (row: any) =>
      row.creation_time ? formatTime(row.creation_time) : "-",
  },
  {
    prop: "confirm_time",
    label: "确认时间",
    // width: "150",
    formatter: (row: any) =>
      row.confirm_time ? formatTime(row.confirm_time) : "配送员未确认",
  },
  {
    prop: "finish_time",
    label: "完成时间",
    // width: "150",
    formatter: (row: any) =>
      row.finish_time ? formatTime(row.finish_time) : "未完成",
  },
  {
    prop: "order_status",
    label: "订单状态",
    width: "90",
    formatter: (row: { order_status: "CREATED" | "INDELIVERY" | "FINISH" }) =>
      ({ CREATED: "已发起", INDELIVERY: "配送中", FINISH: "已完成" }[
        row.order_status
      ]),
  },
];

/**
 * @description 表格操作项
 */
export const tableOptionList = [
  {
    type: "primary",
    name: "详情",
    option: "info",
    permission: "order:getOrder",
  },
  {
    type: "warning",
    name: "配送",
    option: "distribution",
    permission: "order:confirmOrder",
  },
  {
    type: "success",
    name: "完成",
    option: "finish",
    permission: "order:confirmWarehouse",
  },
  {
    type: "danger",
    name: "删除",
    option: "delete",
    permission: "order:delete",
  },
];

/**
 * @description 表格数据
 */
export const tableList = ref([]);

/**
 * @description 添加数据表单实例
 */
export const addDataRef = ref<FormInstance>();

/**
 * @description 添加数据表单规则
 */
export const addDataRules = reactive<FormRules>({
  origin_id: [{ required: true, message: "请选择仓库名称", trigger: "change" }],
  sn: [{ required: true, message: "请输入角色编号", trigger: "blur" }],
  menuIds: [{ required: true, message: "请选择可选菜单", trigger: "blur" }],
});

/**
 * @description 可选权限列表
 */
export const permissionValue = ref([]);

/**
 * @description 已选权限列表
 */
export const permissionList = ref([]);
